package com.bnz.controller;

import com.bnz.User;
import com.bnz.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {
    // 引入service
    private UserService userService;

    // 1、查询全部数据
    @GetMapping("findAll")
    public List<User> findAll(){
        List<User> all = userService.findAll();
        return all;
    }

    // 2、添加数据
    @PostMapping("add")
    public String add(User user){
        userService.add(user);
        return "add-user";
    }
}
